package _05_二叉树;

public class 剑指_Offer_26_树的子结构 {

    // 一个树的子结构，要么是当前整颗树，要么就在左子树，要么就在右子树
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) return false;
        return isSame(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }

    public boolean isSame(TreeNode A, TreeNode B) {
        if (B == null) return true;
        if (A == null || B.val != A.val) return false;
        return isSame(A.left, B.left) && isSame(A.right, B.right);
    }
}
